﻿using System;
using TechTalk.SpecFlow;
using WatiN.Core;

namespace Testicide_BDD
{
    [Binding]
    public class ManagingModulesSteps
    {
        private IE _browser;
        public ManagingModulesSteps()
        {
            _browser = new IE();
        }

            [Given(@"I'm on the Modules page of project number (.*)")]
        public void GivenIMOnTheModulesPageOfProjectNumber(int p0)
        {
            _browser.GoTo("http://localhost:57662/Project");
            var link = _browser.Link("projectDetails_"+p0);
            link.Click();
        }
       
            [When(@"I press createModule")]
        public void WhenIPressCreateModule()
        {
            var link = _browser.Link("createModule");
            link.Click();
        }
            [When(@"I fill in ModuleName textfield with ""(.*)""")]
        public void WhenIFillInModuleNameTextfieldWith(string p0)
        {
            var text = _browser.TextField("Name");
            text.TypeText(p0);
        }

            [When(@"I press Create Module Button")]
        public void WhenIPressCreateModuleButton()
        {
            var button = _browser.Button("Create");
            button.Click();
        }

            [When(@"I press editModule number (.*)")]
        public void WhenIPressEditModuleNumber(int p0)
        {
            var link = _browser.Link("editModule_"+p0);
            link.Click();
        }
            [When(@"I press Edit Module Button")]
        public void WhenIPressEditModuleButton()
        {
            var button = _browser.Button("Edit");
            button.Click();
        }

            [When(@"I click on deleteModule number  (.*)")]
        public void WhenIClickOnDeleteModuleNumber(int p0)
        {
            var link = _browser.Link("deleteModule_"+p0);
            link.Click();
        }
            [When(@"I press Delete Module Button")]
        public void WhenIPressDeleteModuleButton()
        {
            var button = _browser.Button("Delete");
            button.Click();
        }

            [When(@"I click on module number (.*) from the modules list")]
        public void WhenIClickOnModuleNumberFromTheModulesList(int p0)
        {
            var link = _browser.Link("details_" + p0);
            link.Click();
        }

            [Then(@"I should see ""(.*)""")]
        public void ThenIShouldSee(string p0)
        {
            _browser.ContainsText(p0);
        }

            [Then(@"I should see ""(.*)"" in the Modules of Project number (.*)")]
        public void ThenIShouldSeeInTheModulesOfProjectNumber(string p0, int p1)
        {
            _browser.GoTo("http://localhost:57662/Project/Details/"+p1);
            _browser.ContainsText(p0);
        }

            [Then(@"I shouldn't see ""(.*)"" in the Modules of Project number (.*)")]
        public void ThenIShouldnTSeeInTheModulesOfProjectNumber(string p0, int p1)
        {
            _browser.GoTo("http://localhost:57662/Project/Details/" + p1);
            bool x = ! _browser.ContainsText(p0);
        }


        [AfterScenario]
        public void ddd()
        {
            _browser.Dispose();
        }

    }
}
